package com.code.leetcode._202504;
/**删除有序数组中的重复项**/
public class DeleteMultiElement {

    public int removeDuplicates(int[] nums) {
        int n = nums.length, j = 0;
        for (int i = 0; i < n; i++) {
            if (nums[i] != nums[j]) nums[++j] = nums[i];
        }
        return j + 1;
    }

    public int removeDuplicates1(int[] nums) {
        return process(nums, 1);
    }
    int process(int[] nums, int k) {
        int idx = 0;
        for (int x : nums) {
            if (idx < k || nums[idx - k] != x) nums[idx++] = x;
        }
        return idx;
    }
}
